package com.czf.table.controller;


import com.alibaba.fastjson.JSON;
import com.czf.table.config.RequestDataHelper;
import com.czf.table.entity.TestDb;
import com.czf.table.entity.User;
import com.czf.table.mapper.TestDbMapper;
import com.czf.table.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@Slf4j
public class TestController {

    @Resource
    private UserMapper userMapper;

    @Resource
    private TestDbMapper testDbMapper;

    @RequestMapping("/test")
    public void test(@RequestParam("num") int num) {
        System.out.println("1");
        log.info("start");
        RequestDataHelper.setRequestData(new HashMap<String, Object>() {{
            put("num", num);
        }});

        log.info(String.valueOf(System.currentTimeMillis()));
        User user = userMapper.selectById(1);
        log.info("user={}", JSON.toJSONString(user));
    }

    @RequestMapping("/test2")
    public void test2(@RequestParam("num") int num) {

        log.info(String.valueOf(System.currentTimeMillis()));
        TestDb testDb = testDbMapper.selectById(num);
        log.info("user={}", JSON.toJSONString(testDb));
    }


    @RequestMapping("/test1")
    public void test1(@RequestParam("num") int num) {

        log.info(String.valueOf(System.currentTimeMillis()));
        User user = userMapper.selectId(Long.valueOf(num), "czf_user_" + "0" + num);
        log.info("user={}", JSON.toJSONString(user));
    }
}
